package com.wep.fence.geom;

import lombok.Data;

/**
 * @author wep
 * @version 1.0
 * @description:
 * @date 2024/8/22 9:56
 */
@Data
public class GeoPoint {
    public double longitude;
    public double latitude;

    public double coverArea;

    public GeoPoint(double longitude, double latitude) {
        this.longitude = longitude;
        this.latitude = latitude;
    }

    public GeoPoint(double longitude, double latitude, double coverArea) {
        this.longitude = longitude;
        this.latitude = latitude;
        this.coverArea = coverArea;
    }


    @Override
    public String toString() {
        return String.format("(%f, %f)", latitude, longitude);
    }

    /**
     * Calculate the distance between two location
     *
     * @param pt
     * @return
     */
    public double distanceTo(GeoPoint pt) {
        double lat1 = Math.toRadians(this.latitude);
        double lng1 = Math.toRadians(this.longitude);
        double lat2 = Math.toRadians(pt.latitude);
        double lng2 = Math.toRadians(pt.longitude);
        return 6371.01 * Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lng1 - lng2));
    }
}
